home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / Found / FWString / FWPStr.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  29.9 KB  |  873 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPStr.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPSTR_H
  11. #define FWPSTR_H
  12.  
  13. #ifndef FWEXCLIB_H
  14. #include "FWExcLib.h"
  15. #endif
  16.  
  17. #ifndef FWARDYNA_H
  18. #include "FWArDyna.h"
  19. #endif
  20.  
  21. #ifndef SLTXTPAR_H
  22. #include "SLTxtPar.h"
  23. #endif
  24.  
  25. #ifndef SLSTRREP_H
  26. #include "SLStrRep.h"
  27. #endif
  28.  
  29. //========================================================================================
  30. //    Forward declarations
  31. //========================================================================================
  32.  
  33. struct ODIText;
  34. class FW_CReadableStream;
  35. class FW_CWritableStream;
  36. class FW_CString;
  37.  
  38. //========================================================================================
  39. //    CLASS FW_CString
  40. //
  41. //    Characters in strings may occupy one, two, and possibly more bytes.
  42. //  The number of characters in the string is therefore not necessarily equal 
  43. //    to the number of bytes in the string.
  44. //
  45. //    The "length" of the string is measured in characters.
  46. //  The "byteLength" of the string is measured in bytes.
  47. //  The "capacity" of the string is measure in bytes.
  48. //
  49. //========================================================================================
  50.  
  51. class FW_CString
  52. {
  53. public:
  54.     FW_DECLARE_CLASS
  55.     FW_DECLARE_AUTO(FW_CString)
  56.     
  57. //----------------------------------------------------------------------------------------
  58. //    Initialization/Destruction
  59. //
  60. public:
  61.     virtual ~FW_CString();
  62.     FW_CString();
  63.     FW_CString(const FW_CString& other);
  64.     FW_CString(FW_HString rep);
  65.  
  66.     FW_CString(ODIText *text);
  67.     FW_CString(const char* string);
  68.     FW_CString(const char* bytes, FW_ByteCount byteLength);
  69.  
  70.     FW_CString(const char* string, const FW_Locale& locale);
  71.     FW_CString(const char* bytes, FW_ByteCount byteLength, const FW_Locale& locale);
  72.     
  73.     operator FW_HString() const { return fRep; }
  74.     operator FW_HString*();
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    Character access
  78. //
  79. public:
  80.     FW_LChar operator[](FW_CharacterPosition position) const;
  81.         // This function may be expensive for some character sets!
  82.         // Note that it returns a "long character", which may be 1, 2, or possibly more bytes
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    Assignment
  86. //
  87. public:
  88.     FW_CString&  operator=(const FW_CString& other);
  89.     FW_CString&  operator=(ODIText *text);
  90.     FW_CString&  operator=(const char* string);
  91.     
  92. //----------------------------------------------------------------------------------------
  93. //    Storage Manipulation
  94. //
  95. public:
  96.     FW_ByteCount GrowCapacity(FW_ByteCount count);
  97.         // If possible, grow the capacity to count bytes.
  98.         // Return the actual capacity, which may be less or more than count.
  99.     
  100. //----------------------------------------------------------------------------------------
  101. //    Basic accessors
  102. //
  103. public:
  104.     FW_ByteCount GetByteLength() const;
  105.         // Return the number of bytes actually in use for the string
  106.  
  107.     FW_CharacterCount GetCharacterLength() const;
  108.         // Return the number of characters actually in use for the string.
  109.         // Note that with some character sets this may be significantly more expensive
  110.         // to call than GetByteLength!
  111.  
  112.     FW_ByteCount GetCapacity() const;
  113.         // Return the number of bytes that may currently be used without growing capacity.
  114.         // Note that GrowCapacity can be used to extend the capacity beyond the current limit.
  115.     
  116.     void GetLocale(FW_Locale& locale) const;
  117.     
  118.     FW_Boolean IsEmpty() const;
  119.         // Returns true if the string is the empty string, i.e. it's bytelength is 0.
  120.     
  121. //----------------------------------------------------------------------------------------
  122. //    Access to internals, use with caution!
  123. //
  124. public:
  125.     const char* RevealBuffer() const;
  126.         // This function is provided for convenience but is potentially dangerous!!
  127.         // Do not cast away const and then modify the string!
  128.         // Do not save the return value and expect it to be valid after calling
  129.         // any string manipulation method that modifies the string!
  130.         // NOTE: This is not a NUL-terminated string! Use GetByteLength to determine
  131.         // how many bytes may be accessed.
  132.  
  133.     ODIText* RevealODIText() const;
  134.         // This function is provided for convenience but is potentially dangerous!!
  135.         // RevealODIText may be used when passing a String to an OpenDoc interface
  136.         // that takes an ODIText* as an "in" parameter.  Do not use this function to
  137.         // receive a string from OpenDoc!  Also, do not save the return value!
  138.         // Any string manipulation method that modifies the string may invalidate
  139.         // ODIText.
  140.     
  141.     FW_Locale* RevealLocale() const;
  142.         // Used by TextReaders
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // Streaming
  146. public:
  147.  
  148.     static void* Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  149.  
  150.     static void Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  151.  
  152.     FW_CReadableStream& PrivRead(FW_CReadableStream& stream);
  153.  
  154.     FW_CWritableStream& PrivWrite(FW_CWritableStream& stream) const;
  155.  
  156.     friend inline FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CString& string);
  157.     friend inline FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CString& string);
  158.  
  159. //----------------------------------------------------------------------------------------
  160. //    String Manipulation
  161. //
  162. public:
  163.     void Retrieve(char* destination, 
  164.                   FW_ByteCount numberBytes, 
  165.                   FW_BytePosition position) const;
  166.         // Retrieve numberBytes of bytes starting at position.
  167.         // Copy bytes into the destination.
  168.         
  169.     void Delete(FW_ByteCount numberBytes, 
  170.                 FW_BytePosition position);
  171.         // Delete numberBytes bytes, starting at position.
  172.         
  173.     void Insert(const char* bytes, 
  174.                 FW_ByteCount numberBytes,  
  175.                 FW_BytePosition position);
  176.         // Insert bytes into string just before the character at positition.
  177.         // Insert at position GetByteLength() appends the bytes.
  178.         // Insert at position 0 prepends the bytes.
  179.     
  180.     void Insert(ODIText* text, FW_BytePosition position);
  181.         // Insert text at position.
  182.     
  183.     void Insert(const FW_CString& string, FW_BytePosition position);
  184.         // Insert string at position.
  185.     
  186.     void ReplaceAll(ODIText* text);
  187.         // Replace entire contents of this string with text.
  188.     
  189.     void ReplaceAll(const FW_CString& other);
  190.         // Replace entire contents of this string with string.
  191.     
  192.     void ReplaceAll(const char* bytes, FW_ByteCount numberBytes);
  193.         // Replace entire contents of this string with bytes.
  194.  
  195.     void ReplaceAll(const char* string);
  196.         // Replace entire contents of this string with (nul-terminated) string.
  197.     
  198.     void ReplaceAll(const FW_PascalChar* pascalString);
  199.         // Replace entire contents of this string with pascal string.
  200.  
  201.     void ReplaceAll(const char* string, const FW_Locale& newLocale);
  202.         // Replace entire contents of this string with (nul-terminated) string
  203.         // Also replace locale info
  204.  
  205.     void SetEmpty();
  206.         // Remove the entire contents of this string
  207.  
  208.     void SetEmpty(const FW_Locale& newLocale);
  209.         // Remove the entire contents of this string, and replace the locale info
  210.  
  211.     void Append(const FW_CString& other);
  212.         // Append string onto end of this string.
  213.     
  214.     void Append(ODIText* text);
  215.         // Append text onto end of this string.
  216.     
  217.     void Append(const char* bytes, FW_ByteCount numberBytes);
  218.         // Append bytes onto end of this string.
  219.     
  220.     void Append(const char* string);
  221.         // Append (nul-terminated) string onto end of this string.
  222.     
  223.     void Append(char character);
  224.         // Append a single character onto the end of this string.
  225.         
  226.     void Prepend(const FW_CString& other);
  227.         // Prepend string onto beginning of this string.
  228.     
  229.     void Prepend(ODIText* text);
  230.         // Prepend text onto beginning of this string.
  231.     
  232.     void Prepend(const char* bytes, FW_ByteCount numberBytes);
  233.         // Prepend bytes onto beginning of this string.
  234.         
  235.     void Prepend(const char* string);
  236.         // Prepend (nul-terminated) string onto beginning of this string.
  237.         
  238.     void Truncate(FW_BytePosition position);
  239.         // Truncate string at position.  Truncate(0) clears string.
  240.         
  241.     void operator+=(const FW_CString& other);
  242.         // Append string onto the end of this string.
  243.         
  244.     void operator+=(ODIText* text);
  245.         // Append string onto the end of this string.
  246.         
  247.     void operator+=(const char* string);
  248.         // Append (nul-terminated) string onto the end of this string.
  249.         
  250.     void operator+=(char character);
  251.         // Append a single character onto the end of this string.
  252.     
  253. //----------------------------------------------------------------------------------------
  254. //    Exporting Functions
  255. //
  256. public:
  257.     void ExportCString(char* buffer) const;
  258.         // Copy contents of this string to external C string buffer.
  259.         // buffer will contain NUL-terminated C string.
  260.         // It is client's responsibility to ensure buffer is large enough.
  261.  
  262.     void ExportPascal(FW_PascalChar* buffer) const;
  263.         // Copy contents of this string to external 'Pascal' buffer.
  264.         // buffer will contain Pascal string with length byte at buffer[0].
  265.         // It is client's responsibility to ensure buffer is large enough.
  266.  
  267. //----------------------------------------------------------------------------------------
  268. //    Numeric Conversion Functions
  269. //
  270. public:
  271.     long            ParseAsSignedInteger() const;
  272.     long            ParseAsSignedInteger(FW_Boolean& wasValid) const;
  273.     unsigned long    ParseAsUnsignedInteger() const;
  274.     unsigned long    ParseAsUnsignedInteger(FW_Boolean& wasValid) const;
  275.     unsigned long    ParseAsHexadecimalInteger() const;
  276.     unsigned long    ParseAsHexadecimalInteger(FW_Boolean& wasValid) const;
  277.     double            ParseAsRealNumber() const;
  278.     double            ParseAsRealNumber(FW_Boolean& wasValid) const;
  279.     
  280.     void            ReplaceAllAsSignedDecimalInteger(long integer);
  281.     void            ReplaceAllAsUnsignedDecimalInteger(unsigned long integer);
  282.     void            ReplaceAllAsHexadecimalInteger(unsigned long integer);
  283.     void            ReplaceAllAsRealNumber(double real, short fracDigits = 2);
  284.  
  285.     FW_Boolean        IsValidDecimalNumber(FW_Boolean allowDecimalPoint, 
  286.                                          FW_Boolean allowSign) const;
  287.         // Return true if this string contains a valid decimal number (ASCII digits).
  288.         // Set allowDecimalPoint to true to check for a real number.
  289.         // Set allowSign to true to allow a minus sign (negative number).
  290.     FW_Boolean        IsValidHexadecimalNumber() const;
  291.         // Return true if this string contains a valid hexadecimal number (ASCII).
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    Comparison Functions
  295. //
  296. public:
  297.     friend FW_Boolean operator==(const FW_CString& string1, const FW_CString& string2);
  298.     friend FW_Boolean operator!=(const FW_CString& string1, const FW_CString& string2);
  299.     friend FW_Boolean operator<(const FW_CString& string1, const FW_CString& string2);
  300.     friend FW_Boolean operator>(const FW_CString& string1, const FW_CString& string2);
  301.     friend FW_Boolean operator<=(const FW_CString& string1, const FW_CString& string2);
  302.     friend FW_Boolean operator>=(const FW_CString& string1, const FW_CString& string2);
  303.  
  304.     // New in R3:
  305.     FW_Boolean HasSameLocale(const FW_CString& string2);
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    Searching & Substitution Functions
  309. //
  310. public:
  311.  
  312.     void ToUpper();
  313.     void ToLower();
  314.  
  315.     FW_Boolean Substitute(const FW_CString& searchString,
  316.                           const FW_CString& substitutionString);
  317.     
  318.     FW_Boolean FindSubString(const FW_CString& subString,
  319.                              FW_BytePosition &foundPosition,
  320.                              FW_BytePosition startPosition=0) const;
  321.     
  322.     FW_Boolean FindCharacter(FW_LChar character,
  323.                              FW_BytePosition &foundPosition,
  324.                              FW_BytePosition startPosition=0,
  325.                              FW_FindDirection direction=FW_kForwards) const;
  326.     
  327. protected:
  328.     FW_HString    fRep;
  329. };
  330.  
  331. //----------------------------------------------------------------------------------------
  332. // Inline functions
  333. //----------------------------------------------------------------------------------------
  334.  
  335. inline FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CString& string)
  336. {
  337.     return string.PrivRead(stream);
  338. }
  339.         
  340. inline FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CString& string)
  341. {
  342.     return string.PrivWrite(stream);
  343. }
  344.  
  345. //========================================================================================
  346. //    CLASS FW_CAcquireNulTerminatedString
  347. //========================================================================================
  348.  
  349. class FW_CAcquireNulTerminatedString
  350. {
  351. public:
  352.     FW_DECLARE_AUTO(FW_CAcquireNulTerminatedString)
  353.     
  354.     FW_CAcquireNulTerminatedString(const FW_CString& string);
  355.     ~FW_CAcquireNulTerminatedString();
  356.     operator const char*() const
  357.         { return fExportedString; }
  358.     
  359. private:
  360.     char* fExportedString;
  361. };
  362.  
  363. //========================================================================================
  364. //    CLASS FW_CAcquireNulTerminatedString255
  365. //========================================================================================
  366.  
  367. class FW_CAcquireNulTerminatedString255
  368. {
  369. public:
  370.     FW_CAcquireNulTerminatedString255(const FW_CString& string);
  371.     // no destructor necessary
  372.     operator const char*() const
  373.         { return fExportedString; }
  374.     
  375. private:
  376.     char fExportedString[255];
  377. };
  378.  
  379. //========================================================================================
  380. //    FW_CString inline functions
  381. //========================================================================================
  382.  
  383. //----------------------------------------------------------------------------------------
  384. //    FW_CString::GetByteLength
  385. //----------------------------------------------------------------------------------------
  386.  
  387. inline FW_ByteCount FW_CString::GetByteLength() const
  388. {
  389.     return FW_PrivString_GetByteLength(fRep);
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. //    FW_CString::GetCapacity
  394. //----------------------------------------------------------------------------------------
  395.  
  396. inline FW_ByteCount FW_CString::GetCapacity() const
  397. {
  398.     return FW_PrivString_GetCapacity(fRep);
  399. }
  400.  
  401. //----------------------------------------------------------------------------------------
  402. //    FW_CString::IsEmpty
  403. //----------------------------------------------------------------------------------------
  404.  
  405. inline FW_Boolean FW_CString::IsEmpty() const
  406. {
  407.     return GetByteLength() == 0;
  408. }
  409.     
  410. //----------------------------------------------------------------------------------------
  411. //    FW_CString::GetLocale
  412. //----------------------------------------------------------------------------------------
  413.  
  414. inline void FW_CString::GetLocale(FW_Locale& locale) const
  415. {
  416.     FW_PrivString_GetLocale(fRep, &locale);
  417. }
  418.  
  419. //----------------------------------------------------------------------------------------
  420. //    FW_CString::RevealBuffer
  421. //----------------------------------------------------------------------------------------
  422.  
  423. inline const char* FW_CString::RevealBuffer() const
  424. {
  425.     return FW_PrivString_RevealBuffer(fRep);
  426. }
  427.  
  428. //----------------------------------------------------------------------------------------
  429. //    FW_CString::RevealODIText
  430. //----------------------------------------------------------------------------------------
  431.  
  432. inline ODIText* FW_CString::RevealODIText() const
  433. {
  434.     return FW_PrivString_RevealODIText(fRep);
  435. }
  436.  
  437. //----------------------------------------------------------------------------------------
  438. //    FW_CString::RevealLocale
  439. //----------------------------------------------------------------------------------------
  440. inline FW_Locale* FW_CString::RevealLocale() const
  441. {
  442.     return FW_PrivString_RevealLocale(fRep);
  443. }
  444.  
  445. //----------------------------------------------------------------------------------------
  446. //    FW_CString::Retrieve
  447. //----------------------------------------------------------------------------------------
  448.  
  449. inline void FW_CString::Retrieve(char* destination, 
  450.               FW_ByteCount numberBytes, 
  451.               FW_BytePosition position) const
  452. {
  453.     FW_PrivString_Retrieve(fRep, destination, numberBytes, position);
  454. }
  455.  
  456. //----------------------------------------------------------------------------------------
  457. //    FW_CString::Delete
  458. //----------------------------------------------------------------------------------------
  459.  
  460. inline void FW_CString::Delete(FW_ByteCount numberBytes, 
  461.             FW_BytePosition position)
  462. {
  463.     FW_PlatformError error = 0;
  464.     FW_HString rep = FW_PrivString_Delete(fRep, numberBytes, position, &error);
  465.     FW_FailOnError(error);
  466.     fRep = rep;
  467. }
  468.  
  469. //----------------------------------------------------------------------------------------
  470. //    FW_CString::Truncate
  471. //----------------------------------------------------------------------------------------
  472.  
  473. inline void FW_CString::Truncate(FW_BytePosition position)
  474. {
  475.     FW_PlatformError error = 0;
  476.     FW_HString rep = FW_PrivString_Truncate(fRep, position, &error);
  477.     FW_FailOnError(error);
  478.     fRep = rep;
  479. }
  480.  
  481. //----------------------------------------------------------------------------------------
  482. //    FW_CString::Insert
  483. //----------------------------------------------------------------------------------------
  484.  
  485. inline void FW_CString::Insert(const char* bytes, 
  486.             FW_ByteCount numberBytes,  
  487.             FW_BytePosition position)
  488. {
  489.     FW_PlatformError error = 0;
  490.     FW_HString rep = FW_PrivString_InsertBytes(fRep, bytes, numberBytes, position, &error);
  491.     FW_FailOnError(error);
  492.     fRep = rep;
  493. }
  494.  
  495. //----------------------------------------------------------------------------------------
  496. //    FW_CString::Insert
  497. //----------------------------------------------------------------------------------------
  498.  
  499. inline void FW_CString::Insert(ODIText* text, FW_BytePosition position)
  500. {
  501.     FW_PlatformError error = 0;
  502.     FW_HString rep = FW_PrivString_InsertODIText(fRep, text, position, &error);
  503.     FW_FailOnError(error);
  504.     fRep = rep;
  505. }
  506.     
  507. //----------------------------------------------------------------------------------------
  508. //    FW_CString::Insert
  509. //----------------------------------------------------------------------------------------
  510.  
  511. inline void FW_CString::Insert(const FW_CString& string, FW_BytePosition position)
  512. {
  513.     FW_PlatformError error = 0;
  514.     FW_HString rep = FW_PrivString_InsertStringRep(fRep, string.fRep, position, &error);
  515.     FW_FailOnError(error);
  516.     fRep = rep;
  517. }
  518.  
  519. //----------------------------------------------------------------------------------------
  520. //    FW_CString::ReplaceAll
  521. //----------------------------------------------------------------------------------------
  522.  
  523. inline void FW_CString::ReplaceAll(ODIText* text)
  524. {
  525.     FW_PlatformError error = 0;
  526.     FW_HString rep = FW_PrivString_ReplaceAllODIText(fRep, text, &error);
  527.     FW_FailOnError(error);
  528.     fRep = rep;
  529. }
  530.  
  531. //----------------------------------------------------------------------------------------
  532. //    FW_CString::ReplaceAll
  533. //----------------------------------------------------------------------------------------
  534.  
  535. inline void FW_CString::ReplaceAll(const FW_CString& string)
  536. {
  537.     FW_PlatformError error = 0;
  538.     FW_HString rep = FW_PrivString_ReplaceAllStringRep(fRep, string.fRep, &error);
  539.     FW_FailOnError(error);
  540.     fRep = rep;
  541. }
  542.  
  543. //----------------------------------------------------------------------------------------
  544. //    FW_CString::ReplaceAll
  545. //----------------------------------------------------------------------------------------
  546.  
  547. inline void FW_CString::ReplaceAll(const char* bytes, FW_ByteCount numberBytes)
  548. {
  549.     FW_PlatformError error = 0;
  550.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, bytes, numberBytes, &error);
  551.     FW_FailOnError(error);
  552.     fRep = rep;
  553. }
  554.  
  555. //----------------------------------------------------------------------------------------
  556. //    FW_CString::ReplaceAll
  557. //----------------------------------------------------------------------------------------
  558.  
  559. inline void FW_CString::ReplaceAll(const char* string)
  560. {
  561.     FW_PlatformError error = 0;
  562.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  563.     FW_FailOnError(error);
  564.     fRep = rep;
  565. }
  566.  
  567. //----------------------------------------------------------------------------------------
  568. //    FW_CString::ReplaceAll
  569. //----------------------------------------------------------------------------------------
  570.  
  571. inline void FW_CString::ReplaceAll(const FW_PascalChar* string)
  572. {
  573.     FW_PlatformError error = 0;
  574.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, (const char*) (string+1), *string, &error);
  575.     FW_FailOnError(error);
  576.     fRep = rep;
  577. }
  578.  
  579. //----------------------------------------------------------------------------------------
  580. //    FW_CString::Append
  581. //----------------------------------------------------------------------------------------
  582.  
  583. inline void FW_CString::Append(ODIText* text)
  584. {
  585.     FW_PlatformError error = 0;
  586.     FW_HString rep = FW_PrivString_AppendODIText(fRep, text, &error);
  587.     FW_FailOnError(error);
  588.     fRep = rep;
  589. }
  590.     
  591. //----------------------------------------------------------------------------------------
  592. //    FW_CString::Append
  593. //----------------------------------------------------------------------------------------
  594.  
  595. inline void FW_CString::Append(const FW_CString& other)
  596. {
  597.     FW_PlatformError error = 0;
  598.     FW_HString rep = FW_PrivString_AppendStringRep(fRep, other.fRep, &error);
  599.     FW_FailOnError(error);
  600.     fRep = rep;
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    FW_CString::Append
  605. //----------------------------------------------------------------------------------------
  606.  
  607. inline void FW_CString::Append(const char* bytes, FW_ByteCount numberBytes)
  608. {
  609.     FW_PlatformError error = 0;
  610.     FW_HString rep = FW_PrivString_AppendBytes(fRep, bytes, numberBytes, &error);
  611.     FW_FailOnError(error);
  612.     fRep = rep;
  613. }
  614.  
  615. //----------------------------------------------------------------------------------------
  616. //    FW_CString::Append
  617. //----------------------------------------------------------------------------------------
  618.  
  619. inline void FW_CString::Append(const char* string)
  620. {
  621.     FW_PlatformError error = 0;
  622.     FW_HString rep = FW_PrivString_AppendBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  623.     FW_FailOnError(error);
  624.     fRep = rep;
  625. }
  626.  
  627. //----------------------------------------------------------------------------------------
  628. //    FW_CString::Append
  629. //----------------------------------------------------------------------------------------
  630.  
  631. inline void FW_CString::Append(char character)
  632. {
  633.     FW_PlatformError error = 0;
  634.     FW_HString rep = FW_PrivString_AppendBytes(fRep, &character, 1, &error);
  635.     FW_FailOnError(error);
  636.     fRep = rep;
  637. }
  638.  
  639. //----------------------------------------------------------------------------------------
  640. //    FW_CString::Prepend
  641. //----------------------------------------------------------------------------------------
  642.  
  643. inline void FW_CString::Prepend(const FW_CString& string)
  644. {
  645.     FW_PlatformError error = 0;
  646.     FW_HString rep = FW_PrivString_PrependStringRep(fRep, string.fRep, &error);
  647.     FW_FailOnError(error);
  648.     fRep = rep;
  649. }
  650.  
  651. //----------------------------------------------------------------------------------------
  652. //    FW_CString::Prepend
  653. //----------------------------------------------------------------------------------------
  654.  
  655. inline void FW_CString::Prepend(ODIText* text)
  656. {
  657.     FW_PlatformError error = 0;
  658.     FW_HString rep = FW_PrivString_PrependODIText(fRep, text, &error);
  659.     FW_FailOnError(error);
  660.     fRep = rep;
  661. }
  662.  
  663. //----------------------------------------------------------------------------------------
  664. //    FW_CString::Prepend
  665. //----------------------------------------------------------------------------------------
  666.  
  667. inline void FW_CString::Prepend(const char* bytes, FW_ByteCount numberBytes)
  668. {
  669.     FW_PlatformError error = 0;
  670.     FW_HString rep = FW_PrivString_PrependBytes(fRep, bytes, numberBytes, &error);
  671.     FW_FailOnError(error);
  672.     fRep = rep;
  673. }
  674.  
  675. //----------------------------------------------------------------------------------------
  676. //    FW_CString::Prepend
  677. //----------------------------------------------------------------------------------------
  678.  
  679. inline void FW_CString::Prepend(const char* string)
  680. {
  681.     FW_PlatformError error = 0;
  682.     FW_HString rep = FW_PrivString_PrependBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  683.     FW_FailOnError(error);
  684.     fRep = rep;
  685. }
  686.  
  687. //----------------------------------------------------------------------------------------
  688. //    FW_CString::operator+=
  689. //----------------------------------------------------------------------------------------
  690.  
  691. inline void  FW_CString::operator+=(const FW_CString& other)
  692. {
  693.     FW_PlatformError error = 0;
  694.     FW_HString rep = FW_PrivString_AppendStringRep(fRep, other.fRep, &error);
  695.     FW_FailOnError(error);
  696.     fRep = rep;
  697. }
  698.  
  699. //----------------------------------------------------------------------------------------
  700. //    FW_CString::operator+=
  701. //----------------------------------------------------------------------------------------
  702.  
  703. inline void  FW_CString::operator+=(ODIText* text)
  704. {
  705.     FW_PlatformError error = 0;
  706.     FW_HString rep = FW_PrivString_AppendODIText(fRep, text, &error);
  707.     FW_FailOnError(error);
  708.     fRep = rep;
  709. }
  710.  
  711. //----------------------------------------------------------------------------------------
  712. //    FW_CString::operator+=
  713. //----------------------------------------------------------------------------------------
  714.  
  715. inline void  FW_CString::operator+=(const char* string)
  716. {
  717.     FW_PlatformError error = 0;
  718.     FW_HString rep = FW_PrivString_AppendBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  719.     FW_FailOnError(error);
  720.     fRep = rep;
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. //    FW_CString::operator+=
  725. //----------------------------------------------------------------------------------------
  726.  
  727. inline void  FW_CString::operator+=(char character)
  728. {
  729.     FW_PlatformError error = 0;
  730.     FW_HString rep = FW_PrivString_AppendBytes(fRep, &character, 1, &error);
  731.     FW_FailOnError(error);
  732.     fRep = rep;
  733. }
  734.  
  735. //----------------------------------------------------------------------------------------
  736. //    FW_CString::ExportCString
  737. //----------------------------------------------------------------------------------------
  738.  
  739. inline void FW_CString::ExportCString(char* buffer) const
  740. {
  741.     FW_PrivString_ExportCString(fRep, buffer);
  742. }
  743.  
  744. //----------------------------------------------------------------------------------------
  745. //    FW_CString::ExportPascal
  746. //----------------------------------------------------------------------------------------
  747.  
  748. inline void FW_CString::ExportPascal(FW_PascalChar* buffer) const
  749. {
  750.     FW_PrivString_ExportPascalString(fRep, buffer);
  751. }
  752.  
  753. //----------------------------------------------------------------------------------------
  754. //    FW_CString::ToUpper
  755. //----------------------------------------------------------------------------------------
  756.  
  757. inline void FW_CString::ToUpper()
  758. {
  759.     FW_PlatformError error = 0;
  760.     FW_HString rep = FW_PrivString_ToUpper(fRep, &error);
  761.     FW_FailOnError(error);
  762.     fRep = rep;
  763. }
  764.  
  765. //----------------------------------------------------------------------------------------
  766. //    FW_CString::ToLower
  767. //----------------------------------------------------------------------------------------
  768.  
  769. inline void FW_CString::ToLower()
  770. {
  771.     FW_PlatformError error = 0;
  772.     FW_HString rep = FW_PrivString_ToLower(fRep, &error);
  773.     FW_FailOnError(error);
  774.     fRep = rep;
  775. }
  776.  
  777. //----------------------------------------------------------------------------------------
  778. //    FW_CString::Substitute
  779. //----------------------------------------------------------------------------------------
  780.  
  781. inline FW_Boolean FW_CString::Substitute(const FW_CString& searchString,
  782.                                   const FW_CString& substitutionString)
  783. {
  784.     FW_PlatformError error = 0;
  785.     FW_Boolean wasReplaced;
  786.     FW_HString rep = FW_PrivString_Substitute(fRep, searchString.fRep, substitutionString.fRep, &wasReplaced, &error);
  787.     FW_FailOnError(error);
  788.     fRep = rep;
  789.     return wasReplaced;
  790. }
  791.  
  792. //----------------------------------------------------------------------------------------
  793. //    FW_CString::FindSubString
  794. //----------------------------------------------------------------------------------------
  795.  
  796. inline FW_Boolean FW_CString::FindSubString(const FW_CString& subString,
  797.                                       FW_BytePosition &foundPosition,
  798.                                      FW_BytePosition startPosition) const
  799. {
  800.     return FW_PrivString_FindSubString(fRep, subString.fRep, &foundPosition, startPosition);
  801. }
  802.  
  803. //----------------------------------------------------------------------------------------
  804. //    FW_CString::FindCharacter
  805. //----------------------------------------------------------------------------------------
  806.  
  807. inline FW_Boolean FW_CString::FindCharacter(FW_LChar character,
  808.                                      FW_BytePosition &foundPosition,
  809.                                      FW_BytePosition startPosition,
  810.                                      FW_FindDirection direction) const
  811. {
  812.     return FW_PrivString_FindCharacter(fRep, character, &foundPosition, startPosition, direction);
  813. }
  814.  
  815. //----------------------------------------------------------------------------------------
  816. //    FW_CString::operator=
  817. //----------------------------------------------------------------------------------------
  818.  
  819. inline FW_CString& FW_CString::operator=(ODIText *text)
  820. {
  821.     ReplaceAll(text);
  822.     return *this;
  823. }
  824.  
  825. //----------------------------------------------------------------------------------------
  826. //    FW_CString::operator=
  827. //----------------------------------------------------------------------------------------
  828.  
  829. inline FW_CString& FW_CString::operator=(const char* string)
  830. {
  831.     ReplaceAll(string);
  832.     return *this;
  833. }
  834.  
  835. //----------------------------------------------------------------------------------------
  836. //    FW_CString::ReplaceAll
  837. //----------------------------------------------------------------------------------------
  838.  
  839. inline void FW_CString::ReplaceAll(const char* string, const FW_Locale& newLocale)
  840. {
  841.     FW_PlatformError error = 0;
  842.     FW_HString rep = FW_PrivString_AcquireEmptyStringWithLocale(newLocale, &error);
  843.     FW_FailOnError(error);
  844.     rep = FW_PrivString_ReplaceAllBytes(rep, string, FW_PrimitiveStringLength(string), &error);
  845.     FW_FailOnError(error);
  846.     fRep = rep;
  847. }
  848.  
  849. //----------------------------------------------------------------------------------------
  850. //    FW_CString::SetEmpty
  851. //----------------------------------------------------------------------------------------
  852.  
  853. inline void FW_CString::SetEmpty()
  854. {
  855.     FW_PrivString_Release(fRep);
  856.     fRep = FW_PrivString_AcquireEmptyString();
  857. }
  858.  
  859. //----------------------------------------------------------------------------------------
  860. //    FW_CString::SetEmpty
  861. //----------------------------------------------------------------------------------------
  862.  
  863. inline void FW_CString::SetEmpty(const FW_Locale& newLocale)
  864. {
  865.     FW_PrivString_Release(fRep);
  866.     FW_PlatformError error = 0;
  867.     FW_HString rep = FW_PrivString_AcquireEmptyStringWithLocale(newLocale, &error);
  868.     FW_FailOnError(error);
  869.     fRep = rep;
  870. }
  871.  
  872. #endif
  873.